<?php

namespace app\middleware;

class StaticHour
{
    public function handle($request, \Closure $next)
    {
        
        if(!$this->isUpdate())
        {
            
            $this->upUpdate();

//            $push_data = array(
//                'action'     => 'updateCustomerRate',
//                'event'      => 'updateCustomerRate',
//                'page'       => 1,
//                'page_count' => 200
//            );
//            publisher(json_encode($push_data ,true));
           
            longbingView();
        }
        return $next($request);
    }
    public function isUpdate()
    {
        $yesterday = date("Y-m-d",strtotime("-1 day"));
        $key     = 'longbing_auto_static'.$yesterday;
        $uniacid = 'longbing_s';//print_r(delCache($key,$uniacid));exit;
        if(hasCache($key ,$uniacid)) return true;
        return false;
    }
    public function upUpdate()
    {
        
        $yesterday = date("Y-m-d",strtotime("-1 day"));
        $key     = 'longbing_auto_static'.$yesterday;
        $uniacid = 'longbing_s';
        $second = 86400-(time()+8*3600)%86400;
        setCache($key ,time() ,$second,$uniacid);
    }
}
